<?php
namespace app\admin\service;

use app\admin\model\User;
use app\admin\service\interface\UserService;
class UserServiceImpl implements UserService
{
    public function register(string $username,string $password){
        $user = new User();
        $user->username = $username;
        $user->password = $password;
        $user->save();
    }
    public function login_check(string $username,string $password):bool
    {
        # code...
        $user = User::where('username', $username)->findOrEmpty();
        if ($user->isEmpty()) {
           return false;
        }
        if ($user->password != $password) {
            return false;
        }
        return true;
    }
    public function delete(int $id){
        $user = User::where('id', $id)->findOrEmpty();
        if ($user->isEmpty()) {
            throw new \Exception('该用户不存在！');
        }
        return $user->delete();

    }
}
